var mapChangeBarHTML = '<div id="mapchangebar">'+
					'<div id="EDYX" class="mapchangebardiv EDYX">二调影像</div>'+
					'<div id="JCDL" class="mapchangebardiv JCDL">基础地理</div>'+
					'<div id="JCDZ" class="mapchangebardiv JCDZ">基础地质</div>'+
					'<div id="YFFQ" class="mapchangebardiv YFFQ">易发分区</div>'+
					'<div id="FZFQ" class="mapchangebardiv FZFQ">防治规划</div>'+
					'<div id="ZHFB" class="mapchangebardiv ZHFB">灾害分布</div>'+
					'</div>';
					

var mapChangeBarHoverDivHTML ='<div id="hoverdivbar">'+
														'<div id="JCDZHoverDiv" class="hoverDiv">'+
//															'<div class="menuImg"></div>'+
//															'<div id="JCDZHoverContent" class="hoverContent">'+
//															'<div><input id="" type="checkbox" class="hoverCheckbox"/>区域地质</div>'+
//															'<div><input id="" type="checkbox" class="hoverCheckbox"/>地质孔分布</div>'+
//															'</div>'+
														'</div>'+
														'<div id="JCDLHoverDiv" class="hoverDiv">'+
//															'<div class="menuImg"></div>'+
//															'<div id="JCDZHoverContent" class="hoverContent">'+
//															'<div><input id="" type="checkbox" class="hoverCheckbox"/>影像</div>'+
//															'<div><input id="" type="checkbox" class="hoverCheckbox"/>行政区划</div>'+
//															'</div>'+
														'</div>'+
													'</div>';
													

function mapChangeBarInit(){
	//添加mapchangebar
	$("body").append(mapChangeBarHTML);
	//添加hover后的选择效果
	//$("body").append(mapChangeBarHoverDivHTML);
	//初始化默认隐藏
	$("#mapchangebar").hide();
	//隐藏所有的hoverDIV
	hideAllHoverDIV();
	//各种事件的监听
	mapChangeBarEvtInit();
	//注册mapChangeBarDiv的点击事件
	$("#mapChangeBarDiv").click(showAndHideMapChangeBar);
}

function hideAllHoverDIV(){
	$("#DZZHFZHoverDiv").hide();
	$("#JCDZHoverDiv").hide();
	$("#JCDLHoverDiv").hide();
	$("#SWDZHoverDiv").hide();
	$("#GCDZHoverDiv").hide();
	$("#HJDZHoverDiv").hide();
	$("#DZZHHoverDiv").hide();
}

//对mapchangebar上的按钮进行监听
function mapChangeBarEvtInit(){
	$("#GPSKZ").click(clickGPSKZEvt);
	$("#DZZHFZ").hover(overMapChangeBarDiv);
	$("#JCDZ").hover(overMapChangeBarDiv);
	$("#SWDZ").hover(overMapChangeBarDiv);
	$("#GCDZ").hover(overMapChangeBarDiv);
	$("#HJDZ").hover(overMapChangeBarDiv);
	$("#DZZH").hover(overMapChangeBarDiv);
	$("#JCDL").hover(overMapChangeBarDiv);
	//解决移出事件的bug//////////////////
	$("#GPSKZ").hover(overMapChangeBarDiv);
	$("#EDYX").hover(overMapChangeBarDiv);
	$("#SWYX").hover(overMapChangeBarDiv);
	////////////////////////////////////
	
	$("#EDYX").click(onclickMapChange);
	$("#JCDL").click(onclickMapChange);
	$("#JCDZ").click(onclickMapChange);
	$("#YFFQ").click(onclickMapChange);
	$("#FZFQ").click(onclickMapChange);
	$("#ZHFB").click(onclickMapChange);
}

//GPS控制点击事件
function clickGPSKZEvt(){
	
}

//hover移入的事件
function overMapChangeBarDiv(evt){
	var divID = evt.srcElement.id;
	hideAllHoverDIV();
	switch(divID){
	case 'DZZHFZ':
		$("#DZZHFZHoverDiv").show();
		break;
	case 'JCDZ':
		$("#JCDZHoverDiv").show();
		break;
	case 'SWDZ':
		$("#SWDZHoverDiv").show();
		break;
	case 'GCDZ':
		$("#GCDZHoverDiv").show();
		break;
	case 'HJDZ':
		$("#HJDZHoverDiv").show();
		break;
	case 'DZZH':
		$("#DZZHHoverDiv").show();
		break;
	case 'JCDL':
		$("#JCDLHoverDiv").show();
		break;
	}
}

function showAndHideMapChangeBar(){
	if($("#mapChangeBarDiv").attr("class")=="mapChangeBarHide"){//如果是隐藏，那么打开
		$("#mapChangeBarDiv").attr("class","mapChangeBarShow");
		$("#mapchangebar").show('slide', { direction: 'right' }, 300, null);
	}else{//如果已经打开，那么隐藏
		 $("#mapchangebar").hide('slide', { direction: 'right' }, 300, null);
		$(".mapChangeBarShow").attr("class","mapChangeBarHide");
	}
	hideAllHoverDIV();
}

function changeMapEvt(evt){
	
}

//“各种影像的切换”事件
function onclickMapChange(evt){
	var divID = evt.srcElement.id;
	var restUrl;
	removeEdyx();////移除二调影像
	if(floatlayer!= null){
		map.removeLayer(floatlayer);
		floatlayer =null;
	}
	//map.events.unregister('moveend', map,mapMoveEndEventCallback);
	switch(divID){
	case 'EDYX':
		addEDYXLayers();
		changeLegendPanelForJCDL();
		return ;
		break;
	case 'JCDL':
		/*if(floatlayer!= null){
			map.removeLayer(floatlayer);
			floatlayer=null;
		}*/
		//mapMoveEndEventCallback();
		changeLegendPanelForJCDL();
		return ;
		break;
	case 'JCDZ':
		restUrl='http://172.26.0.11/ArcGIS/rest/services/420000JCDZ/MapServer/export';
		$("#legendpanelContent").show();
		break;
	case 'YFFQ':
		restUrl='http://172.26.0.11/ArcGIS/rest/services/420000YFFQ/MapServer/export';
		changeLegendPanelForFZFQ();
		break;
	case 'FZFQ':
		restUrl='http://172.26.0.11/ArcGIS/rest/services/420000FZQH/MapServer/export';
		changelegendPanelForFZGH();
		break;
	case 'ZHFB':
		restUrl='http://172.26.0.11/ArcGIS/rest/services/420000DZFB/MapServer/export';
		loadLegendPanel();
		//map.events.unregister('moveend', map,mapMoveEndEventCallback);
		//map.events.register('moveend', map,mapMoveEndEventCallback);
		//mapMoveEndEventCallback();
		break;
	}

	var layer = new OpenLayers.Layer.ArcGIS93Rest("Hubei",restUrl,{transparent:true}, 
			{
				singleTile: true, numZoomLevels: 64,ratio:1,isBaseLayer:false
			});
	
	floatlayer = layer;
	map.addLayer(layer);
	map.setLayerIndex(layer,1);
	$("#slider").slider("option","value",100);
}

var globalLegendPanel=null;

function changelegendPanelForFZGH(){
	if(globalLegendPanel!=null){
		globalLegendPanel.remove();
	}
	$("#legendpanelContent").hide();
	$("#legendpanel").hide();
	var fzghpannel = 
	   '<div id="fzghpannel" class="fzghPannel">'+
	   		'<img id="fzghpannelIMGDiv" src="image/legendpanel/fzgh.jpg" class="imgFZGH"/>'+
	   '<div id="fzghBtn" class="showLegendPanel"></div>'+
         '</div>';
	$("body").append(fzghpannel);
	globalLegendPanel = $("#fzghpannel");
	fzghPanelInit();
}

function fzghPanelInit(){
	$("#fzghBtn").attr("title","收缩");
	$("#fzghBtn").click(hideAndShowFZGHPanel)
}

function hideAndShowFZGHPanel(evt){
	var divId = evt.srcElement.id;
	if($("#"+divId).attr("class")=="showLegendPanel"){//如果展开，那么收缩
		$("#"+divId).attr("title","展开");
		$("#"+divId).attr("class","hideLegendPanel");
		$("#fzghpannel").stop().animate({
			left: "-294px"
        }, { duration: 500});
	}else{//如果收缩，那么展开
		$("#"+divId).attr("title","收缩");
		$("#"+divId).attr("class","showLegendPanel");
		$("#fzghpannel").stop().animate({
			left: "0px",
        }, { duration: 500 });
	}
}

function changeLegendPanelForFZFQ(){
	if(!globalLegendPanel!=null){
		globalLegendPanel.remove();
	}
	$("#legendpanelContent").hide();
	$("#legendpanel").hide();
	var fzfqpannel = 
	   '<div id="fzfqpannel" class="fzfqPannel">'+
	   		'<img id="fzfqIMGDiv" src="image/legendpanel/yffq.JPG" class="imgFZFQ"/>'+
	   '<div id="fzfqBtn" class="showLegendPanel"></div>'+
         '</div>';
	$("body").append(fzfqpannel);
	globalLegendPanel=$("#fzfqpannel");
	fzfqPanelInit();
}

function fzfqPanelInit(){
	$("#fzfqBtn").attr("title","收缩");
	$("#fzfqBtn").click(hideAndShowFZFQPanel)
}

function hideAndShowFZFQPanel(evt){
	var divId = evt.srcElement.id;
	if($("#"+divId).attr("class")=="showLegendPanel"){//如果展开，那么收缩
		$("#"+divId).attr("title","展开");
		$("#"+divId).attr("class","hideLegendPanel");
		$("#fzfqpannel").stop().animate({
			left: "-294px"
        }, { duration: 500});
	}else{//如果收缩，那么展开
		$("#"+divId).attr("title","收缩");
		$("#"+divId).attr("class","showLegendPanel");
		$("#fzfqpannel").stop().animate({
			left: "0px",
        }, { duration: 500 });
	}
}
///////////////////////
function changeLegendPanelForJCDL(){
	if(!globalLegendPanel!=null){
		globalLegendPanel.remove();
	}
	$("#legendpanelContent").hide();
	$("#legendpanel").hide();
	var fzfqpannel = 
	   '<div id="jcdlpannel" class="jcdlPannel">'+
	   		'<div class="gradeGroup">重大灾害&nbsp;&nbsp;&nbsp;&nbsp;应急调查&nbsp;&nbsp;&nbsp;&nbsp;应急监测&nbsp;&nbsp;&nbsp;&nbsp;群测群防</div>'+
								   //'<div class="legendImgDiv">'+
								   		'<div class="BTLegendImg"><div id="gradeZDZH" class="zhdgroupImg"></div><div id="gradeYJDC" class="zhdgroupImg"></div><div id="gradeYJJC" class="zhdgroupImg"></div><div id="gradeQCQF" class="zhdgroupImg"></div></div>'+
								   //'</div>'+
								   '<div id="jcdlBtn" class="showLegendPanel"></div>'+
         '</div>';
	$("body").append(fzfqpannel);
	globalLegendPanel=$("#jcdlpannel");
	jcdlPanelInit();
	//loadZhdByType(xmin,ymin,xmax,ymax);//加载相应的分类灾害点
}

function jcdlPanelInit(){
	$("#jcdlBtn").attr("title","收缩");
	$("#jcdlBtn").click(hideAndShowJCDLPanel)
}

function hideAndShowJCDLPanel(evt){
	var divId = evt.srcElement.id;
	if($("#"+divId).attr("class")=="showLegendPanel"){//如果展开，那么收缩
		$("#"+divId).attr("title","展开");
		$("#"+divId).attr("class","hideLegendPanel");
		$("#jcdlpannel").stop().animate({
			left: "-294px"
        }, { duration: 500});
	}else{//如果收缩，那么展开
		$("#"+divId).attr("title","收缩");
		$("#"+divId).attr("class","showLegendPanel");
		$("#jcdlpannel").stop().animate({
			left: "0px",
        }, { duration: 500 });
	}
}
